<?php
namespace app\admin\logic;

class PatrolRecordLogic extends BaseLogic {

    /**
     * 获取巡店明细查询条件
     * @param $branchid
     * @param $floorid
     * @param $cp_type
     * @param $username
     * @param $start_time
     * @param $end_time
     * @return array
     */
    public function get_search_pr_maps($branchid,$floorid,$cp_type,$username,$start_time,$end_time){
        $maps = [];
        $maps[] = ['status','=',1];

        if($branchid != -1){
            $f_maps = [];
            $f_maps[] = ['branchid','=',$branchid];
            $floorids = model('floor')->get_column($f_maps,'id');
            $maps[] = ['floorid','in',$floorids];
        }

        if($floorid != -1){
            $maps[] = ['floorid','=',$floorid];
        }

        if($cp_type != -1){
            $maps[] = ['cp_type','=',$cp_type];
        }

        if(!empty($username)){
            $u_maps = [];
            $u_maps[] = ['username','=',$username];
            $openids = model('user')->get_column($u_maps,'openid');
            $maps[] = ['openid','in',$openids];
        }

        if(!empty($start_time) && !empty($end_time)){
            $maps[] = ['end_time','between',[$start_time,$end_time]];
        }

        return $maps;
    }

    /**
     * 获取工位查询条件
     * @param $branchid
     * @param $floorid
     * @param $regionid
     * @return array
     */
    public function get_search_pr_ws_maps($branchid,$floorid,$regionid){
        $maps = [];

        $f_maps = [];
        $f_maps[] = ['branchid','=',$branchid];
        $floorids = model('floor')->get_column($f_maps,'id');

        $m_maps = [];
        $m_maps[] = ['floorid','in',$floorids];
        $regionids = model('region')->get_column($m_maps,'id');
        $maps[] = ['regionid','in',$regionids];


        $m_maps = [];
        $m_maps[] = ['floorid','=',$floorid];
        $regionids = model('region')->get_column($m_maps,'id');
        $maps[] = ['regionid','in',$regionids];

        $maps[] = ['regionid','=',$regionid];
        return $maps;
    }
}